home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-02-26 | 4.1 KB | 145 lines |
- '
- ' 3d Spinner - Maverick of Nina Software
- '
- ' v0.14
- '
- ' 4 - 10 - 93
- '
- ' MODIFICATIONS: v0.14 - Includes distance compensation.
- '
- ' NOTE: The documentation has been provided for those who need to
- ' learn from this program. One interesting thing which can
- ' be learnt is that comments take time when the program is
- ' run in the interpreter. What this means is for the prog-
- ' ram to be viewed at its best remove the comments before
- ' running (OR compile it).
- '
- Set Buffer 20
- Degree
- Screen Open 0,320,256,16,0
- Flash Off
- Curs Off
- Hide
- Cls 0
- Double Buffer
- Autoback 0
- '
- Close Editor
- Close Workbench
- '
- Dim PNTS(50,12),FACES(50,3),SYN(360),COZ(360),OBJ(5,2),EYE(3)
- Global PNTS(),SYN(),COZ(),S,FACES(),OBJ(),EYE()
- SETUP
- PITCH=0
- YAW=0
- DELTADEG=15
- '
- ' Main Loop
- '
- Repeat
- If Not Fire(1)
- Add PITCH,DELTADEG*(Jup(1)-Jdown(1)),DELTADEG To 360
- Add YAW,DELTADEG*(Jleft(1)-Jright(1)),DELTADEG To 360
- Else
- Add EYE(2),DELTADEG*(Jup(1)-Jdown(1))
- Add EYE(1),DELTADEG*(Jleft(1)-Jright(1))
- End If
- ROTATE[YAW,PITCH]
- Screen Swap
- Wait Vbl
- Cls 0
- Until Mouse Key<>0
- '
- ' End of program
- '
- Procedure SETUP
- '
- ' This procedure is used to setup the arrays. SYN contains the sine
- ' values for deg=0 to 360. COZ is the same for the cosine values.
- ' PNTS contains the points for the PNTSect:-
- ' PNTS(n,1) = x1 PNTS(n,2) = y1 PNTS(n,3) = z1 ...
- ' PNTS(n,9) = z3
- '
- For COUNT=0 To 360
- SYN(COUNT)=10000*Sin(COUNT)
- COZ(COUNT)=10000*Cos(COUNT)
- Next COUNT
- Restore DATER
- Repeat
- Inc PNTS(0,0)
- For COUNT=1 To 3
- Read PNTS(PNTS(0,0),COUNT)
- Next COUNT
- Read WORD$
- Until WORD$="ENDPNTS"
- Repeat
- Inc FACES(0,0)
- For COUNT=0 To 3
- Read FACES(FACES(0,0),COUNT)
- Next COUNT
- Read WORD$
- Until WORD$="ENDDATA"
- EYE(0)=0
- EYE(1)=0
- EYE(2)=0
- EYE(3)=0
- OBJ(1,0)=0
- OBJ(1,1)=0
- OBJ(1,2)=150
- '
- ' The following stores the number of faces in the PNTSect.
- '
- '
- ' The following contains the data for all the points in the PNTSect.
- ' Three points per polygon. "CONT" is meaningless. "ENDDATA" marks
- ' the end of the data for the PNTSect.
- ' The first field in the PNTSect is the colour of the polygon.
- ' For the hidden face calculations to be consistant the points MUST
- ' be defined in an anticlockwise direction when looking at the face
- ' "HEAD-ON" (ie. from out of the PNTSect in)
- '
- DATER:
- Data 0,-30,0,"GO"
- Data 30,30,30,"GO"
- Data -30,30,30,"GO"
- Data 30,30,-30,"GO"
- Data -30,30,-30,"ENDPNTS"
- Data 8,1,3,2,"GO"
- Data 4,1,2,4,"GO"
- Data 6,1,4,5,"GO"
- Data 4,1,5,3,"GO"
- Data 15,2,5,4,"GO"
- Data 14,2,3,5,"ENDDATA"
- End Proc
- Procedure ROTATE[YAW,PITCH]
- For COUNT=1 To FACES(0,0)
- PNTS(COUNT,4)=((PNTS(COUNT,3)*SYN(YAW))/10000)-((PNTS(COUNT,1)*COZ(YAW))/10000)
- PNTS(COUNT,6)=((PNTS(COUNT,3)*COZ(YAW))/10000)+((PNTS(COUNT,1)*SYN(YAW))/10000)
- PNTS(COUNT,5)=((PNTS(COUNT,2)*COZ(PITCH))/10000)-((PNTS(COUNT,6)*SYN(PITCH))/10000)
- PNTS(COUNT,6)=((PNTS(COUNT,2)*SYN(PITCH))/10000)+((PNTS(COUNT,6)*COZ(PITCH))/10000)
- Next COUNT
- For COUNT=1 To FACES(0,0)
- X1=PNTS(FACES(COUNT,1),4)
- Y1=PNTS(FACES(COUNT,1),5)
- Z1=PNTS(FACES(COUNT,1),6)
- X2=PNTS(FACES(COUNT,2),4)
- Y2=PNTS(FACES(COUNT,2),5)
- Z2=PNTS(FACES(COUNT,2),6)
- X3=PNTS(FACES(COUNT,3),4)
- Y3=PNTS(FACES(COUNT,3),5)
- Z3=PNTS(FACES(COUNT,3),6)
- X1=(160*(EYE(1)+X1))/(OBJ(1,2)-Z1)
- X2=(160*(EYE(1)+X2))/(OBJ(1,2)-Z2)
- X3=(160*(EYE(1)+X3))/(OBJ(1,2)-Z3)
- Y1=(128*(EYE(2)+Y1))/(OBJ(1,2)-Z1)
- Y2=(128*(EYE(2)+Y2))/(OBJ(1,2)-Z2)
- Y3=(128*(EYE(2)+Y3))/(OBJ(1,2)-Z3)
- A=(Y1*(Z2-Z3))+(Y2*(Z3-Z1))+(Y3*(Z1-Z2))
- B=(X1*(Z3-Z2))+(X2*(Z1-Z3))+(X3*(Z2-Z1))
- C=(X1*(Y2-Y3))+(X2*(Y3-Y1))+(X3*(Y1-Y2))
- Ink FACES(COUNT,0)
- If C>0
- Polygon X1+160,Y1+128 To X2+160,Y2+128 To X3+160,Y3+128
- End If
- Next COUNT
- End Proc